package hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author Lu Ruotong
 * @date 2022/3/16 9:07
 */
public class getTable {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        conf.set("hbase.zookeeper.quorum", "192.168.116.11");
        HTable table = new HTable(conf, "Student");
        Get get1 = new Get(Bytes.toBytes("1"));
        Get get2 = new Get(Bytes.toBytes("2"));
        Get get3 = new Get(Bytes.toBytes("3"));
        Get get4 = new Get(Bytes.toBytes("4"));
        Get get5 = new Get(Bytes.toBytes("5"));
        Get get6 = new Get(Bytes.toBytes("6"));
        Get get7 = new Get(Bytes.toBytes("7"));
        Get get8 = new Get(Bytes.toBytes("8"));
        Get get9 = new Get(Bytes.toBytes("9"));
        Get get10 = new Get(Bytes.toBytes("10"));
//        long start = System.currentTimeMillis();
        System.out.println("COLUMN\t\t\t\t\t\tCELL");
        Result res1 = table.get(get1);
        Result res2 = table.get(get2);
        Result res3 = table.get(get3);
        Result res4 = table.get(get4);
        Result res5 = table.get(get5);
        Result res6 = table.get(get6);
        Result res7 = table.get(get7);
        Result res8 = table.get(get8);
        Result res9 = table.get(get9);
        Result res10 = table.get(get10);
//        for增强(for循环)---不用考虑循环对象的长度
//        keyvalue -- 定义一个新的变量
        for (KeyValue kv : res1.raw()) {
            //    KeyValue：读取一个单元格的值
            System.out.print(new String(kv.getFamily()) + ":" + new String(kv.getQualifier()) + "\t\t\t\t");
            System.out.println( "value1=" + new String(kv.getValue()));
        }
        for (KeyValue kv : res2.raw()) {
            //    KeyValue：读取一个单元格的值
            System.out.print(new String(kv.getFamily()) + ":" + new String(kv.getQualifier()) + "\t\t\t\t");
            System.out.println( "value2=" + new String(kv.getValue()));
        }
        for (KeyValue kv : res3.raw()) {
            //    KeyValue：读取一个单元格的值
            System.out.print(new String(kv.getFamily()) + ":" + new String(kv.getQualifier()) + "\t\t\t\t");
            System.out.println( "value3=" + new String(kv.getValue()));
        }
        for (KeyValue kv : res4.raw()) {
            //    KeyValue：读取一个单元格的值
            System.out.print(new String(kv.getFamily()) + ":" + new String(kv.getQualifier()) + "\t\t\t\t");
            System.out.println( "value4=" + new String(kv.getValue()));
        }
        for (KeyValue kv : res5.raw()) {
            //    KeyValue：读取一个单元格的值
            System.out.print(new String(kv.getFamily()) + ":" + new String(kv.getQualifier()) + "\t\t\t\t");
            System.out.println( "value5=" + new String(kv.getValue()));
        }
        for (KeyValue kv : res6.raw()) {
            //    KeyValue：读取一个单元格的值
            System.out.print(new String(kv.getFamily()) + ":" + new String(kv.getQualifier()) + "\t\t\t\t");
            System.out.println( "value6=" + new String(kv.getValue()));
        }
        for (KeyValue kv : res7.raw()) {
            //    KeyValue：读取一个单元格的值
            System.out.print(new String(kv.getFamily()) + ":" + new String(kv.getQualifier()) + "\t\t\t\t");
            System.out.println( "value7=" + new String(kv.getValue()));
        }
        for (KeyValue kv : res8.raw()) {
            //    KeyValue：读取一个单元格的值
            System.out.print(new String(kv.getFamily()) + ":" + new String(kv.getQualifier()) + "\t\t\t\t");
            System.out.println( "value8=" + new String(kv.getValue()));
        }
        for (KeyValue kv : res9.raw()) {
            //    KeyValue：读取一个单元格的值
            System.out.print(new String(kv.getFamily()) + ":" + new String(kv.getQualifier()) + "\t\t\t\t");
            System.out.println( "value9=" + new String(kv.getValue()));
        }
        for (KeyValue kv : res10.raw()) {
            //    KeyValue：读取一个单元格的值
            System.out.print(new String(kv.getFamily()) + ":" + new String(kv.getQualifier()) + "\t\t\t\t");
            System.out.println( "value10=" + new String(kv.getValue()));
        }
//        long end = System.currentTimeMillis();
//        System.out.println("5 row(s)  in  " + (double) (end - start) / 1000 + "  seconds");
    }
}
